<template>
  <button :class="classObject"
            :disabled="disabled || loading"
            @click="onButtonClick">

    <slot name="content">
      <i v-if="loading"><img class="loading" src="@/assets/icon/loading.png" alt=""></i>
      <p v-else>{{ text }}</p>
    </slot>
  </button>
</template>

<script>
export default {
  name: "wsl-button",
  props: {
    type: {
      type: String,
      default: 'primary'
    },
    plain: Boolean,
    round: Boolean,
    disabled: Boolean,
    circle: Boolean,
    loading: Boolean,
    size: {type: String,default: 'default'},
  },
  data() {
    return {
      text:'',
      classObject:{
        normal:this.type==='normal', primary:this.type==='primary', success:this.type==='success', info:this.type==='info', warning:this.type==='warning', danger:this.type==='danger',
        round:this.round,
        circle:this.circle,
        medium:this.size==='medium', small:this.size==='small', mini:this.size==='mini',
        disabled:this.disabled || this.loading
      }
    }
  },
  computed: {

  },
  methods:{
    onButtonClick(){
      console.log('点击按钮',this.text)
    }
  },
  created() {
    if(this.$slots.default){
      this.text = this.$slots.default[0].text
    }
  }
}
</script>

<style lang="less" scoped>

button {
  padding: 10px 20px;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  box-sizing: border-box;
  color: #fff;
}
button img{
  width: 14px;
  height: 14px;
  margin: 0 auto;
}
.color(@bgColor,@bdColor) {
  background-color: @bgColor;
  border: 1px solid @bdColor;
}

.color-all(@normal,@hover,@active) {
  .color(@normal, @normal);
  &:hover {
    .color(@hover, @hover);
  }
  &:active {
    .color(@active, @active);
  }
}

.normal {
  .color-all(#fff, #ECF5FF, #ECF5FF);
  color: #606266;
  border: 1px solid #DCDFE6;

  &:hover {
    color: #409eff;
    border: 1px solid #C6E2FF;
  }

  &:active {
    border: 1px solid #3A8EE6;
  }
}

.primary {
  .color-all(#409EFF, #66B1FF, #3A8EE6)
}

.success {
  .color-all(#67C23A, #85CE61, #5DAF34)
}

.info {
  .color-all(#909399, #A6A9AD, #82848A)
}

.warning {
  .color-all(#E6A23C, #EBB563, #CF9236)
}

.danger {
  .color-all(#F56C6C, #F78989, #DD6161)
}

.round {
  border-radius: 20px;
}
.disabled{
  cursor: not-allowed;
}
.circle{
  border-radius: 50%;
  padding: 10px 10px;
  //.size(40px,40px);
  width: 40px;
  height: 40px;
}
.loading{
  animation: rotate 2s linear infinite;
  pointer-events: none;
}
@keyframes rotate {
  from {
    transform: rotate(0deg)
  }
  to {
    transform: rotate(359deg)
  }
}

.medium{
  padding: 8px 20px;
  font-size: 14px;
}
.small{
  padding: 7px 15px;
  font-size: 12px;
}
.mini{
  padding: 5px 15px;
  font-size: 12px;
}
</style>